import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    component: () => import("../views/Home.vue"),
    children: [
      {
        path: "/home",
        redirect: "/home/index",
      },
      {
        path: "/home/circle",
        component: () => import("../views/home/Circle.vue"),
        children: [
          // {
          //   path: "/home/circle",
          //   redirect: "/home/circle/recommend",
          // },
          {
            path: "/home/circle/recommend",
            component: () => import("../views/home/Circle/Recommend.vue"),
          },
        ],
      },
      {
        path: "/home/index",
        component: () => import("../views/home/Index.vue"),
      },
      {
        path: "/home/markt",
        component: () => import("../views/home/Markt.vue"),
      },
      {
        path: "/home/userinfo",
        component: () => import("../views/home/UserInfo.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.getItem("token")) {
            next();
          } else {
            next("/login");
          }
        },
      },
    ],
  },
  {
    path: "/login",
    component: () => import("../views/Login.vue"),
  },
  {
    path: "/city",
    component: () => import("../views/City.vue"),
  },
  {
    path: "/exhibition",
    component: () => import("../views/Exhibition.vue"),
  },
  {
    path: "/mine",
    component: () => import("../views/Mine.vue"),
  },
  {
    path: "/register",
    component: () => import("../views/Register.vue"),
  },
  {
    path: "/circleinfo/:id",
    component: () => import("../views/CircleInfo.vue"),
  },
  {
    path: "/ticketinfo/:id",
    component: () => import("../views/TicketInfo.vue"),
    props: true,
  },
  {
    path: "/cart",
    component: () => import("../views/Cart.vue"),
  },
  {
    path: "/detail/:id",
    component: () => import("../views/Detail.vue"),
  },
  { path: "/order", component: () => import("../views/Order.vue") },

  {
    path: "/:pathMatch(.*)*",
    component: () => import("../views/NotFound.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

export default router;
